<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>01_原生操作DOM和JQ的区别</title>
    <style>
      .left {
        float: left;
      }
      div {
        width: 200px;
        height: 200px;
        border: 1px solid red;
      }

      .right {
        float: right;
      }
    </style>
    <script>
      // 1.原生操作DOM的形式
      window.onload = function () {
        //   获取节点
        var div1 = document.getElementsByTagName("div")[0];
        var div2 = document.getElementById("A1");
        var div3 = document.getElementsByClassName("A2")[0]; //取第一个
        // console.log(div1);
        // console.log(div2);
        // console.log(div3);
        // 改变背景颜色
        div1.style.backgroundColor = "blue";
        div2.style.backgroundColor = "red";
        div3.style.backgroundColor = "green";
      };
    </script>

    <script src="../源码/jquery-3.3.1.min.js"></script>
    <script>
      $(function () {
        var $div1 = $("div")[4];
      });
    </script>
  </head>
  <body>
    <div class="left">
      <div>1</div>
      <div id="A1">2</div>
      <div class="A2">3</div>
    </div>

    <div class="right">
      <div>1</div>
      <div id="AA1">2</div>
      <div class="A2">3</div>
    </div>
  </body>
</html>
